From a7b9f3ebdfc761d6f21c83cab976f785633bf75f Mon Sep 17 00:00:00 2001
From: Mike Dalessio <mike.dalessio@gmail.com>
Date: Thu, 20 May 2021 13:38:54 -0400
Subject: [PATCH] fix: avoid segfault at exit when using custom memory
 functions

This extends the fix introduced by 956534e to Windows processes
dynamically loading libxml2.

Closes #256.
---
 parser.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/parser.c b/parser.c
index c9312fa4..255bd254 100644
--- a/parser.c
+++ b/parser.c
@@ -14672,7 +14672,8 @@ xmlInitParser(void) {
 	return;
 
 #if defined(_WIN32) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
-	atexit(xmlCleanupParser);
+    if (xmlFree == free)
+        atexit(xmlCleanupParser);
 #endif
 
 #ifdef LIBXML_THREAD_ENABLED
-- 
GitLab

